/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package View.ClusterizationPanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTable;

/**
 *
 * @author vf
 */
public class CustomOptionsActionsTable extends JTable implements MouseListener{
    CustomOptionsActionsWindow main;
    public CustomOptionsActionsTable(){}
    public void setParent(CustomOptionsActionsWindow main){
        this.setModel(new CustomOptionsActionsTableModel(main));
        this.main=main;
        addMouseListener(this);
        getColumn("No").setMaxWidth(20);
        getColumn("Color").setPreferredWidth(20);
        setDefaultRenderer(Color.class, new ColorRenderer(true));
        this.setSize(300,300);
        this.setOpaque(true);
        this.setVisible(true);
        Dimension maxSize=new Dimension(640,(getRowCount()*20));
        this.setMaximumSize(maxSize);
        repaint();
    }

    public void assignCluster(int actionIndex, int clusterIndex) {
        ((CustomOptionsActionsTableModel)getModel()).assignCluster(actionIndex, clusterIndex);
        repaint();
    }

    public int getActionAssignedTo(int clusterIndex, int actionIndex) {
        return ((CustomOptionsActionsTableModel)getModel()).getActionAssignedTo(clusterIndex, actionIndex);
    }

    public int getActionsCountAssignedTo(int clusterIndex) {
        return ((CustomOptionsActionsTableModel)getModel()).getActionsCountAssignedTo(clusterIndex);
    }

    public void clearAssignedCluster(int actionIndex) {
        ((CustomOptionsActionsTableModel)getModel()).clearAssignedCluster(actionIndex);
        repaint();
    }

    void clearAllActionsAssignedTo(int clusterIndex) {
        ((CustomOptionsActionsTableModel)getModel()).clearAllActionsAssignedTo(clusterIndex);
        repaint();
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseReleased(MouseEvent e) {
        updateActionSelection();
    }

    public void mouseEntered(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void mouseExited(MouseEvent e) {
        //throw new UnsupportedOperationException("Not supported yet.");
    }

    public void updateActionSelection(){
        main.updateActionSelection(this.getSelectedRows());
    }


}
